package com.kuaimacode.kframework.agent.services.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.agent.services.content.ContentService;
import com.kuaimacode.kframework.agent.services.master.MasterService;
import com.kuaimacode.kframework.mybatis.mapper.user.OrderDispatchMapper;
import com.kuaimacode.kframework.mybatis.models.user.OrderDispatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 中元
 * @date 2019/04/08
 */
@Service
public class OrderDispatchService extends ServiceImpl<OrderDispatchMapper, OrderDispatch> {
	@Autowired
	private ContentService contentService;
	@Autowired
	private MasterService masterServices;
	@Autowired
	private OrderService orderServices;
	/**
	 *  分页查找所有的数据
	 * @param pageNum 当前页码，从1开始
	 * @param pageSize  一页显示多少行
	 * @return
	 */
	public PageInfo<OrderDispatch> findAll(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<OrderDispatch> datas = baseMapper.selectList(null);
		return new PageInfo<OrderDispatch>(datas);
	}


	/**
	 *  分页查找所有的数据
	 * @param pageNum 当前页码，从1开始
	 * @param pageSize  一页显示多少行
	 * @return
	 */
	public PageInfo<OrderDispatch> findAll(int pageNum, int pageSize, String agentId, int status) {
		QueryWrapper<OrderDispatch> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("agent_id",agentId);
		queryWrapper.eq("status",status);
		queryWrapper.orderByDesc("id");
		PageHelper.startPage(pageNum, pageSize);
		List<OrderDispatch> datas = baseMapper.selectList(queryWrapper);
		return new PageInfo<OrderDispatch>(datas);
	}

	/**
	 * 根据订单id查询单条记录
	 * @param orderId
	 * @return
	 */
	public OrderDispatch getByOrderId(Long orderId, int status){
		QueryWrapper<OrderDispatch> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("order_id",orderId);
		queryWrapper.eq("status",status);
		OrderDispatch orderDispatch = baseMapper.selectOne(queryWrapper);
		return orderDispatch;
	}


}

